<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>企业广告管理管理</title>
	<meta name="decorator" content="default"/>
	<%@include file="/WEB-INF/views/include/treeview.jsp" %>
	<script src="http://webapi.amap.com/maps?v=1.3&key=589381d73924ac781b542765046f3235&callback=init"></script>
	<script type="text/javascript">
		$(document).ready(function() {
			//$("#name").focus();
			$("#inputForm").validate({
				submitHandler: function(form){
                    var ids = [], nodes = tree.getCheckedNodes(true);
                    for(var i=0; i<nodes.length; i++) {
                        ids.push(nodes[i].id);
                    }
                    $("#category").val(ids);
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
            var setting = {check:{enable:true,nocheckInherit:true},view:{selectedMulti:false},
                data:{simpleData:{enable:true}},callback:{beforeClick:function(id, node){
                        tree.checkNode(node, !node.checked, true, true);
                        return false;
                    }}};



            // 用户-菜单
            var zNodes=[
                    <c:forEach items="${categorys}" var="category">{id:"${category.id}", pId:"${not empty category.parent.id?category.parent.id:0}", name:"${not empty category.parent.id?category.name:'名称'}"},
                </c:forEach>];
            // 初始化树结构
            var tree = $.fn.zTree.init($("#categoryTree"), setting, zNodes);
            // 不选择父节点
            tree.setting.check.chkboxType = { "Y" : "ps", "N" : "s" };
            // 默认选择节点
            var ids = "${hkEnterpriseAdv.category}".split(",");
            for(var i=0; i<ids.length; i++) {
                var node = tree.getNodeByParam("id", ids[i]);
                try{tree.checkNode(node, true, false);}catch(e){}
            }
            // 默认展开全部节点
            tree.expandAll(true);
        });
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/adv/hkEnterpriseAdv/">企业广告管理列表</a></li>
		<li class="active"><a href="${ctx}/adv/hkEnterpriseAdv/form?id=${hkEnterpriseAdv.id}">企业广告管理<shiro:hasPermission name="adv:hkEnterpriseAdv:edit">${not empty hkEnterpriseAdv.id?'修改':'添加'}</shiro:hasPermission><shiro:lacksPermission name="adv:hkEnterpriseAdv:edit">查看</shiro:lacksPermission></a></li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="hkEnterpriseAdv" action="${ctx}/adv/hkEnterpriseAdv/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<sys:message content="${message}"/>		
		<div class="control-group">
			<label class="control-label">标题：</label>
			<div class="controls">
				<form:input path="title" htmlEscape="false" maxlength="200" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">地址：</label>
			<div class="controls">
				<form:hidden id="imgSrc" path="imgSrc" htmlEscape="false" maxlength="200" class="input-xlarge"/>
				<sys:ckfinder input="imgSrc" type="files" uploadPath="/hkEnterpriseAdv" selectMultiple="false"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">链接：</label>
			<div class="controls">
				<form:input path="link" htmlEscape="false" maxlength="200" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">说明：</label>
			<div class="controls">
				<form:input path="note" htmlEscape="false" maxlength="200" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">序号：</label>
			<div class="controls">
				<form:input path="imgRank" htmlEscape="false" maxlength="200" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">所属分类：</label>
			<div class="controls">
				<div id="categoryTree" class="ztree" style="margin-top:3px;float:left;"></div>
				<form:hidden path="category"/>

			</div>
		</div>
		<div class="control-group">
			<label class="control-label">状态：</label>
			<div class="controls">
				<form:select path="state" class="input-xlarge ">
					<form:option value="" label=""/>
					<form:options items="${fns:getDictList('yes_no')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
				</form:select>
			</div>
		</div>

		<div class="control-group">
			<label class="control-label">积分：</label>
			<div class="controls">
				<form:input path="integral" htmlEscape="false" maxlength="11" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">视频长度：</label>
			<div class="controls">
				<form:input path="vedioLength" htmlEscape="false" maxlength="11" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">物品：</label>
			<div class="controls">
				<form:input path="goodsIds" htmlEscape="false" maxlength="200" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">标签：</label>
			<div class="controls">
				<form:checkboxes path="tags" items="${fns:getDictList('hk_enterprise_adv_tag')}" itemLabel="label" itemValue="value" htmlEscape="false" class=""/>
      	</div>
		</div>
		<div class="control-group">
			<label class="control-label">管理分类：</label>
			<div class="controls">
				<form:select path="manageCategory" class="input-xlarge ">
					<form:option value="" label=""/>
					<form:options items="${fns:getDictList('hk_category')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
				</form:select>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">国家：</label>
			<div class="controls">
				<form:hidden path="countryId"/>
				<form:input path="country" htmlEscape="false" maxlength="32" class="input-xlarge "/>

			</div>
		</div>
		<div class="control-group">
			<label class="control-label">省：</label>
			<div class="controls">
				<form:hidden path="provinceId"/>
				<form:input path="province" htmlEscape="false" maxlength="32" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">市：</label>
			<div class="controls">
				<form:hidden path="cityId"/>
				<form:input path="city" htmlEscape="false" maxlength="32" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">总积分：</label>
			<div class="controls">
				<form:input path="integralCount" htmlEscape="false" maxlength="11" class="input-xlarge "/>
			</div>
		</div>
		<form:hidden path="enterpriseId"/>

		<div class="control-group">
			<label class="control-label">企业名称：</label>
			<div class="controls">
				<form:input path="enterpriseName" htmlEscape="false" maxlength="100" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">是否评论：</label>
			<div class="controls">
				<form:select path="comment" class="input-xlarge ">
					<form:option value="" label=""/>
					<form:options items="${fns:getDictList('yes_no')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
				</form:select>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">开始时间：</label>
			<div class="controls">
				<input name="beginDate" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate "
					value="<fmt:formatDate value="${hkEnterpriseAdv.beginDate}" pattern="yyyy-MM-dd HH:mm:ss"/>"
					onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',isShowClear:false});"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">结束时间：</label>
			<div class="controls">
				<input name="endDate" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate "
					value="<fmt:formatDate value="${hkEnterpriseAdv.endDate}" pattern="yyyy-MM-dd HH:mm:ss"/>"
					onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',isShowClear:false});"/>
			</div>
		</div>
		<div    class="control-group" >
			<label class="control-label">左键点击选择地点：</label>
			<div  class="controls"  id="container" style="width: 600px;height:400px;">
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">经度：</label>
			<div class="controls">
				<form:input path="longitude" htmlEscape="false" maxlength="100" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">纬度：</label>
			<div class="controls">
				<form:input path="latitude" htmlEscape="false" maxlength="100" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">封面图片：</label>
			<div class="controls">
				<form:hidden id="coverImgSrc" path="coverImgSrc" htmlEscape="false" maxlength="200" class="input-xlarge"/>
				<sys:ckfinder input="coverImgSrc" type="images" uploadPath="/hkEnterpriseAdv" selectMultiple="false"/>

			</div>
		</div>
		<div class="control-group">
			<label class="control-label">封面图片链接：</label>
			<div class="controls">
				<form:input path="coverLink" htmlEscape="false" maxlength="200" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">备注：</label>
			<div class="controls">
				<form:textarea path="remarks" htmlEscape="false" rows="4" maxlength="100" class="input-xxlarge "/>
			</div>
		</div>
		<div class="form-actions">
			<shiro:hasPermission name="adv:hkEnterpriseAdv:edit"><input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;</shiro:hasPermission>
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
		</div>
	</form:form>
	<script>
        var longitude=116.455241;
        var  latitude=39.906005;
        var marker;
        var areas=[];
        <c:forEach items="${areas}" var="item">
        var area={id:"${item.id}",name:"${item.name}",type:"${item.type}" };
        areas.push(area);
        </c:forEach>
        <c:if test="${not empty hkEnterpriseAdv.longitude}"> longitude=${hkEnterpriseAdv.longitude};   latitude=${hkEnterpriseAdv.latitude}; </c:if>
        function init(){
            var map = new AMap.Map('container', {
                center: [longitude, latitude],
                zoom: 20
            });
            marker = new AMap.Marker({
                map:map,
                draggable: false,  //是否可拖动
                position:[longitude,latitude]
            });
            //marker.setAnimation('AMAP_ANIMATION_BOUNCE');
            map.plugin(["AMap.ToolBar"], function() {
                map.addControl(new AMap.ToolBar());
            });
            //为地图注册click事件获取鼠标点击出的经纬度坐标
            var clickEventListener = map.on('click', function(e) {
                $("#longitude").val(e.lnglat.getLng());
                $("#latitude").val(e.lnglat.getLat());

                map.remove(marker);
                marker = new AMap.Marker({
                    map:map,
                    draggable: false,  //是否可拖动
                    position:[e.lnglat.getLng(),e.lnglat.getLat()]
                });
                map.getCity(function(data) {
                    if (data['province'] && typeof data['province'] === 'string') {
                        console.log(data)

                        for(var p in areas){
                            if(data['province'].indexOf(areas[p].name)>-1){
                                document.getElementById('provinceId').value = areas[p].id;
                                document.getElementById('province').value = areas[p].name;
                            }
                            if(data['city']==""&&areas[p].type=="3"){
                                if(data['province'].indexOf(areas[p].name)>-1){
                                    document.getElementById('cityId').value =areas[p].id;
                                    document.getElementById('city').value =areas[p].name;
                                }
                            }
                            else{
                                if(data['city'].indexOf(areas[p].name)>-1){
                                    document.getElementById('cityId').value =areas[p].id;
                                    document.getElementById('city').value =areas[p].name;
                                }
                            }
                            document.getElementById('countryId').value ="1";
                            document.getElementById('country').value ="中国";
                        }


                    }
                })
            });
        }
	</script>
</body>
</html>